define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {  
                   data:'',
                 
                };
            },
            el: '#pageBookDetail',
            created: function() {
                this.fetchData();
            },
            methods: {
                fetchData: function() {
                    this.loadOrder();
                    
                } ,
                // onShow:function(){
                //    this.loadOrder();
                // },
                 setData:function(arr){
                  for( var i in arr){
                     this[i] = arr[i];
                  }
             },

                loadOrder(reload = 0) {
                  var that = this;  
                  if(reload==1){
                      app.setPageData("oms/order",{reload:1});
                   }                
                  app.get("apiv2/order/find", {
                    order_sn: this.$route.params.order_sn
                  }, function (res) {
                    that.loading = 0;
                    if (res.code != 200) {
                      app.alert(res.msg);
                      return;
                    }
                    that.data= res.data;
                     
                  });
                },
              //确认接单
              book_receiving(order_sn){
                
                var that = this;
                app.get('/mall/dining_table_book/receiving', {
                        order_sn: order_sn
                    }, function(data) {
                        if (data.code == 200) {
                           app.alert('操作成功');
                          that.loadOrder(1);
                        } else {
                            app.alert(data.msg);
                        }
                    });
              },
              //取消
              book_cancel(order_sn){
                
                var that = this;
                app.get('/mall/dining_table_book/cancel', {
                        order_sn: order_sn
                   
                    }, function(data) {
                        if (data.code == 200) {
                           app.alert('操作成功');
                          that.loadOrder(1);
                        } else {
                            app.alert(data.msg);
                        }
                    });
              },
               //取消
              book_complete(order_sn){
                
                var that = this;
                app.get('/mall/dining_table_book/complete', {
                        order_sn: order_sn
                   
                    }, function(data) {
                        if (data.code == 200) {
                           app.alert('操作成功');
                          that.loadOrder(1);
                        } else {
                            app.alert(data.msg);
                        }
                    });
              }
             
 
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
